<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .active {
        color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button
        v-for="item in list"
        :class="{ active: curs.includes(item) }"
        @click="onClick(item)"
      >
        {{ item }}
      </button>
    </div>

    <script src="../lib/vue3.js"></script>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            list: ["帅气", "钱多", "话少", "死得早"],
            curs: ["帅气", "钱多"],
          };
        },

        methods: {
          onClick(str) {
            if (this.curs.includes(str)) {
              // 移除
              this.curs = this.curs.filter((item) => item !== str);
            } else {
              // 添加
              this.curs.push(str);
            }
          },
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
